package com.hx.thread.sync;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author jxlgcmh
 * @date 2019-07-31 21:33
 */
public class SyncExample {

    public static void main(String[] args) {
        SyncExample example = new SyncExample();
        ExecutorService executorService = Executors.newCachedThreadPool();
        // 使用的是同一个对象
        executorService.submit(() -> example.func1());
        executorService.submit(() -> example.func1());
    }

    public void func1() {
        synchronized (this) {
            for (int i = 0; i < 5; i++) {
                System.out.print(i + "\t");
            }
        }
    }
}
